<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller
{
    public function _initialize()
    {
        if(cookie('Yname')&&cookie('Ypwd')){
            $this->success('检测到保存的账号，自动登录中...',U('Text/show'),3);
        }
    }
    public function index()
    {
            $Please_sign_in="请登录";
            $Name="姓名";
            $Password="密码";
            $Remember_me="记住密码";
            $Sign_in="登录";
            $true="1";
            $this->assign('sign',$Please_sign_in);
            $this->assign('Name',$Name);
            $this->assign('Password',$Password);
            $this->assign('Remember',$Remember_me);
            $this->assign('Sign_in',$Sign_in);
            $this->assign('true',$true);
            $this->display();
    }
    public function zhuc(){
        $Please_sign_in="请注册";
        $Name="姓名";
        $Password="密码";
        $Sign_in="注册";
        $this->assign('sign',$Please_sign_in);
        $this->assign('Name',$Name);
        $this->assign('Password',$Password);
        $this->assign('Sign_in',$Sign_in);
        if(I('name')&&I('pwd')){//是否提交
            $m['name']=md5(md5(I('name')).C('YAN'));
            $find=M('admin')->where($m)->find();
            if(!$find==false){//是否已注册
                $this->error('账号已存在，请直接登录！',U('index'),3);
            }else{//是否已注册
                $map['name']=md5(md5(I('name')).C('YAN'));
                $map['pwd']=md5(md5(I('pwd')).C('YAN'));
                $result=M('admin')->add($map);
                if(!$result==false){//是否添加成功！
                    $this->success('注册成功！',U('index'),3);
                }else{//是否添加成功！
                    $this->error('注册失败！',U('zhuc'),3);
                }
            }
        }else{//是否提交
            $this->display();
        }
    }
}